package demo1;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 具体装饰器：去除重复单词
 */
public class DistinctDecorator extends WordReaderDecorator {
    public DistinctDecorator(WordReader wordReader) {
        super(wordReader);
    }

    @Override
    protected List<String> decorate(List<String> words) {
        List<String> distinctWords = words.stream()
                .distinct() // 去重
                .collect(Collectors.toList());
        System.out.printf("装饰器-去重：原始%d个单词，去重后%d个，列表：%s%n",
                words.size(), distinctWords.size(), distinctWords);
        return distinctWords;
    }
}
